using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Scene;
using MicroMsg.Storage;
using MicroMsg.UI.Page;
using MicroMsg.UI.UserContrl;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.Util
{
	public abstract class ChatContainerPage : BasePage, IChatContainerPage
	{
		private const string TAG = "ChatContainerPage";
		public static ItemCacheService mItemCacheService = new ItemCacheService();
		public static ChatPageCtrl cuChatPage;
		private static ChatContainerPage currentContainerPage;
		public ChatPageCtrl mChatPageCtrl;
		private bool isBkUiInContainer = true;
		protected IApplicationBar oldbar;
		protected IApplicationBar ChatAppBar;
		public static ChatContainerPage getCuChatContainerPage()
		{
			return ChatContainerPage.currentContainerPage;
		}
		public static ChatPageCtrl getCuChatPage()
		{
			if (ChatContainerPage.cuChatPage == null)
			{
				ChatContainerPage.cuChatPage = new ChatPageCtrl();
			}
			return ChatContainerPage.cuChatPage;
		}
		public static string getCuChatPageTalker()
		{
			if (ChatContainerPage.cuChatPage != null)
			{
				return ChatContainerPage.cuChatPage.cuUser;
			}
			return "";
		}
		public static ChatPageCtrl tryGetCuChatPage()
		{
			return ChatContainerPage.cuChatPage;
		}
		public static List<EggItem> getContainChatEggs(string content)
		{
			List<EggItem> list = new List<EggItem>();
			EggItemList eggProfile = EggProfileMgr.getEggProfile();
			if (eggProfile != null)
			{
				using (List<EggItem>.Enumerator enumerator = eggProfile.eggList.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						EggItem current = enumerator.get_Current();
						if (content.Contains(current.KeyWord))
						{
							list.Add(current);
						}
						else
						{
							if (content.ToLower().Contains(current.KeyWord) || content.ToUpper().Contains(current.KeyWord))
							{
								list.Add(current);
							}
						}
					}
				}
			}
			return list;
		}
		public static void doChatEggs(List<EggItem> eggItemList, ChatEggsCtrl.EggType eggType)
		{
			ChatPageCtrl chatPageCtrl = ChatContainerPage.getCuChatPage();
			chatPageCtrl.CheckChatEggsCtrl();
			chatPageCtrl.mChatEggsCtrl.startChatEggs(eggItemList, eggType);
		}
		public static void UseContainer(ChatContainerPage container, object[] argObj)
		{
			if (container == null)
			{
				Log.smethod_5("ChatContainerPage", "UseContainer container == null");
				return;
			}
			if (container == ChatContainerPage.getCuChatContainerPage())
			{
				ChatContainerPage cuChatContainerPage = ChatContainerPage.getCuChatContainerPage();
				if (cuChatContainerPage.HasChatPageShow())
				{
					cuChatContainerPage.RestoreAppBar();
					cuChatContainerPage.mChatPageCtrl.OnPageOut();
				}
				cuChatContainerPage.SaveAppBar();
				cuChatContainerPage.mChatPageCtrl = ChatContainerPage.cuChatPage;
				cuChatContainerPage.mChatPageCtrl.set_Visibility(0);
				cuChatContainerPage.ShowBkContent(1);
				cuChatContainerPage.mChatPageCtrl.OnPageIn(argObj, cuChatContainerPage);
				return;
			}
			ChatContainerPage cuChatContainerPage2 = ChatContainerPage.getCuChatContainerPage();
			if (cuChatContainerPage2 != null)
			{
				cuChatContainerPage2.RemoveChatPage();
			}
			container.GetChatContainerPanel().get_Children().Add(ChatContainerPage.cuChatPage);
			container.mChatPageCtrl = ChatContainerPage.cuChatPage;
			container.mChatPageCtrl.set_Visibility(0);
			container.ShowBkContent(1);
			container.SaveAppBar();
			ChatContainerPage.cuChatPage.OnPageIn(argObj, container);
			ChatContainerPage.currentContainerPage = container;
		}
		public static void GoToChatPage(BasePage originPage, string username, string nickName = null, string qqNickName = null, string pageStrArgs = null)
		{
			if (WebMMMgr.IsWebMMOnline)
			{
				originPage.get_Dispatcher().BeginInvoke(delegate
				{
					NetSceneStatusNotify netSceneStatusNotify = new NetSceneStatusNotify();
					netSceneStatusNotify.doScene(MMStatusNotifyType.MM_STATUSNOTIFY_ENTERSESSION, AccountMgr.curUserName, username);
				});
			}
			MMTheme.GetInstance().DelayInitThemes();
			ChatContainerPage.getCuChatPage();
			if (originPage == null)
			{
				Log.smethod_5("ChatContainerPage", "GoToChatPage originPage == null");
				return;
			}
			object[] array;
			if (pageStrArgs != null)
			{
				array = new object[]
				{
					default(object),
					default(object),
					default(object),
					pageStrArgs
				};
			}
			else
			{
				if (qqNickName != null)
				{
					array = new object[]
					{
						default(object),
						default(object),
						qqNickName
					};
				}
				else
				{
					if (nickName != null)
					{
						array = new object[]
						{
							default(object),
							nickName
						};
					}
					else
					{
						array = new object[1];
					}
				}
			}
			array[0] = username;
			if (originPage is ChatContainerPage)
			{
				ChatContainerPage.UseContainer(originPage as ChatContainerPage, array);
				return;
			}
			if (MainPage.mainPageInstance == null)
			{
				Log.smethod_5("ChatContainerPage", "GoToChatPage,mainPageInstance == null");
				return;
			}
			PageManager.getInstance().ClearStackToChatPage();
			ChatContainerPage.UseContainer(MainPage.mainPageInstance, array);
		}
		public static void CloseChatPage()
		{
			if (ChatContainerPage.currentContainerPage == null)
			{
				return;
			}
			ChatContainerPage.currentContainerPage.HideChatPage();
		}
		protected bool PreOnBackKeyPress(CancelEventArgs cancelEventArgs_0)
		{
			if (this.HasChatPageShow())
			{
				if (this.mChatPageCtrl.OnBackKeyPress(cancelEventArgs_0))
				{
					this.HideChatPage();
				}
				cancelEventArgs_0.set_Cancel(true);
				base.OnBackKeyPress(cancelEventArgs_0);
				return true;
			}
			return false;
		}
		protected void PreOnPageBack()
		{
			if (this.HasChatPageShow())
			{
				this.mChatPageCtrl.OnPageBack();
			}
		}
		protected void PreOnPageForward(Uri targetPage)
		{
			if (this.HasChatPageShow())
			{
				this.mChatPageCtrl.OnPageForward(targetPage);
			}
		}
		protected void PreOnPageOut()
		{
			this.RemoveChatPage();
		}
		protected bool PreIsAlertMsgNeedShow(ChatMsg chatMsg_0, ref bool bool_0)
		{
			if (!this.HasChatPageShow())
			{
				return false;
			}
			bool_0 = this.mChatPageCtrl.IsAlertMsgNeedShow(chatMsg_0);
			return true;
		}
		public bool HasAttachChatPage()
		{
			return this.mChatPageCtrl != null;
		}
		public bool HasChatPageShow()
		{
			return this.mChatPageCtrl != null && this.mChatPageCtrl.get_Visibility() != 1;
		}
		public void RemoveChatPage()
		{
			if (this.mChatPageCtrl == null)
			{
				return;
			}
			if (this.mChatPageCtrl.get_Visibility() == null)
			{
				this.ShowBkContent(0);
				this.mChatPageCtrl.OnPageOut();
				this.RestoreAppBar();
			}
			Panel chatContainerPanel = this.GetChatContainerPanel();
			chatContainerPanel.get_Children().Remove(this.mChatPageCtrl);
			ChatContainerPage.currentContainerPage = null;
			this.mChatPageCtrl = null;
		}
		public void HideChatPage()
		{
			if (this.mChatPageCtrl == null)
			{
				return;
			}
			if (this.mChatPageCtrl.get_Visibility() != null)
			{
				return;
			}
			ItemFlyInAndOutAnimations.TitleFlyOut(this.mChatPageCtrl);
			this.mChatPageCtrl.set_Visibility(1);
			base.get_Dispatcher().BeginInvoke(delegate
			{
				this.RestoreAppBar();
				base.get_Dispatcher().BeginInvoke(delegate
				{
					if (this.mChatPageCtrl != null)
					{
						this.mChatPageCtrl.OnPageOut();
					}
				});
				this.ShowBkContent(0);
				this.resumeFromChat();
				base.UpdateLayout();
				base.get_Dispatcher().BeginInvoke(delegate
				{
					ItemFlyInAndOutAnimations.FlyItemsIn();
				});
			});
		}
		protected virtual void resumeFromChat()
		{
		}
		private void ShowBkContent(Visibility visibility_0)
		{
			List<UIElement> bkContents = this.GetBkContents();
			if (bkContents == null)
			{
				return;
			}
			using (List<UIElement>.Enumerator enumerator = bkContents.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					UIElement current = enumerator.get_Current();
					current.set_Visibility(visibility_0);
				}
			}
			if (visibility_0 == null)
			{
				if (!this.isBkUiInContainer)
				{
					this.StartResumeBkUI();
					this.isBkUiInContainer = true;
					return;
				}
			}
			else
			{
				if (this.isBkUiInContainer)
				{
					this.StartRemoveBkUI();
					this.isBkUiInContainer = false;
				}
			}
		}
		protected virtual void StartRemoveBkUI()
		{
		}
		protected virtual void StartResumeBkUI()
		{
		}
		protected override void RootFrameChange(double double_0)
		{
			if (this.HasChatPageShow())
			{
				this.mChatPageCtrl.RootFrameChange(double_0);
			}
		}
		protected virtual void SaveAppBar()
		{
			this.oldbar = base.get_ApplicationBar();
			base.set_ApplicationBar(this.ChatAppBar);
		}
		private void RestoreAppBar()
		{
			this.ChatAppBar = base.get_ApplicationBar();
			base.get_Dispatcher().BeginInvoke(delegate
			{
				base.set_ApplicationBar(this.oldbar);
			});
		}
		public void StartSipListen()
		{
			base.BeginListenForSIPChanged();
		}
		public void EndSipListen()
		{
			base.EndListenForSipChanged();
		}
		public ChatContainerPage GetRealPage()
		{
			return this;
		}
		public abstract List<UIElement> GetBkContents();
		public abstract Panel GetChatContainerPanel();
	}
}
